package com.wcll.www;
import java.sql.*;
import java.util.*;
public class GenBean {
	private int id;
	private String name;
	private String password;
	private String email;
	private final int PAGE_ROWS = 20;
	private java.util.Date createtime;
	private static Connection con=null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public java.util.Date getCreatetime() {
		return createtime;
	}
	public void setCreatetime(java.util.Date createtime) {
		this.createtime = createtime;
	}
	public static Connection getCon() throws ClassNotFoundException, SQLException {
		if(con==null){
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost/jobs?useUnicode=true&characterEncoding=UTF8","root","");
		}
		return con;
	}
	public static void setCon(Connection con) {
		GenBean.con = con;
	}
	public ArrayList<GenBean> getGen(int currage){
		ArrayList<GenBean> a = new ArrayList<GenBean>();
		int n = (currage-1)*this.PAGE_ROWS;
		try{
			con = GenBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select * from job_generics order by id desc limit "+n+","+this.PAGE_ROWS);
			while(rs.next()){
				GenBean gb = new GenBean();
				gb.setId(rs.getInt("id"));
				gb.setName(rs.getString("gen_name"));
				gb.setPassword(rs.getString("gen_password"));
				gb.setEmail(rs.getString("gen_email"));
				gb.setCreatetime(new java.util.Date(rs.getDate("create_time").getTime()));
				a.add(gb);
			}
			rs.close();
			st.close();
		}catch(Exception e){}
		return a;
	}
	public boolean deleGen(int id){
		boolean flags = false;
		try{
			con = GenBean.getCon();
			Statement st = con.createStatement();
			st.execute("delete from job_generics where id="+id);
			if(st.getUpdateCount()==1){
				flags = true;
			}
		}catch(Exception e){}
		return flags;
	}
	public int getCounts(){
		int pages = 0;
		double totals;
		
		try{
			con = GenBean.getCon();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select count(*) as a from job_generics");
			while(rs.next()){
				totals = (double)rs.getInt("a");
				pages = (int)Math.ceil(totals/this.PAGE_ROWS);
			}
		}catch(Exception e){}
		return pages;
	}
}
